package com.family.business.custom.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import com.family.base.util.BaseAction;
import com.family.business.custom.dto.CustomDto;
import com.family.business.custom.service.CustomIService;

@Namespace("/custom")
@ParentPackage("struts-default")
@Service("customAction")
@Scope(value="prototype")
public class CustomAction extends BaseAction{
	
	private static final long serialVersionUID = 8824758801369554161L;
	
	@Resource(name="customModel")
	private CustomModel customModel;
	@Resource(name="customService")
	private CustomIService customService;

	@Override
	public Object getModel() {
		return this.customModel;
	}
	
	@Action(value="get",results={@Result(name="SUCCESS",location="/custom.jsp")})
	public String selectget(){
		CustomDto dto = this.customService.getCustom(this.customModel.getId());
		this.customModel.setEntity(dto);
		return SUCCESS;
	}
	
	@Action(value="save",results={@Result(name="succ",location="/custom.jsp")})
	public String save(){
		System.out.println(11111);
		this.customService.save(this.customModel.getEntity());
		this.customModel.setId(this.customModel.getEntity().getId());
		return selectget();
	}

}
